<?php /*a:5:{s:54:"D:\phpstudy_pro\WWW\tp\app\admin\view\article\add.html";i:1655925677;s:49:"D:\phpstudy_pro\WWW\tp\app\admin\view\layout.html";i:1640261441;s:54:"D:\phpstudy_pro\WWW\tp\app\admin\view\common\meta.html";i:1655800829;s:56:"D:\phpstudy_pro\WWW\tp\app\admin\view\common\header.html";i:1640261441;s:56:"D:\phpstudy_pro\WWW\tp\app\admin\view\common\footer.html";i:1640261441;}*/ ?>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">

<script src="/static/layui/layui.js"></script>
<script type="text/javascript" src="http://code.jquery.com/jquery-3.5.1.slim.min.js"></script>
<script src="/static/layui/js-3.1.1.min.js"></script>
    <title>VeeCMF 通用后台管理系统 - 快速接口开发 快速后台开发</title>
    <link rel="stylesheet" href="/static/layui/css/layui.css">
</head>
<body>
<div class="layui-layout layui-layout-admin">
    <div class="layui-header">
    <div class="layui-logo layui-hide-xs layui-bg-black">VeeCMF</div>
    <!-- 头部区域（可配合layui 已有的水平导航） -->
    <ul class="layui-nav layui-layout-left">
        <!-- 移动端显示 -->
        <li class="layui-nav-item layui-show-xs-inline-block layui-hide-sm" lay-header-event="menuLeft">
            <i class="layui-icon layui-icon-spread-left"></i>
        </li>
        <?php foreach($layout_menu_list as $key=>$vo): if($vo['position'] == '1'): if($vo['show'] == '1'): if($vo['status'] == '1'): if(is_array($promise_menu_id) == true): foreach($promise_menu_id as $idx=>$menu_id): if($menu_id == $vo['id']): ?>
                        <li class="layui-nav-item layui-hide-xs"><a href="<?php echo htmlentities($vo['route']); ?>"><?php echo htmlentities($vo['title']); ?></a></li>
                    <?php endif; ?>
                <?php endforeach; else: ?>
                    <li class="layui-nav-item layui-hide-xs"><a href="<?php echo htmlentities($vo['route']); ?>"><?php echo htmlentities($vo['title']); ?></a></li>
                <?php endif; ?>
            <?php endif; ?>
            <?php endif; ?>
            <?php endif; ?>
        <?php endforeach; ?>
<!--        <li class="layui-nav-item">-->
<!--            <a href="javascript:;">工具</a>-->
<!--            <dl class="layui-nav-child">-->
<!--                <dd><a href="">尚未开发</a></dd>-->
<!--            </dl>-->
<!--        </li>-->
    </ul>
    <ul class="layui-nav layui-layout-right">
        <li class="layui-nav-item layui-hide layui-show-md-inline-block">
            <a href="javascript:;">
                <img src="<?php echo htmlentities($rootData['avatar_src']); ?>" class="layui-nav-img">
                <?php echo htmlentities($rootData['root_name']); ?>
            </a>
            <dl class="layui-nav-child">
<!--                <dd><a href="">个人资料</a></dd>-->
<!--                <dd><a href="">个人设置</a></dd>-->
                <dd><a href="/admin/login/logout">退出登录</a></dd>
            </dl>
        </li>
        <li class="layui-nav-item" lay-header-event="menuRight" lay-unselect>
            <a href="javascript:;">
                <i class="layui-icon layui-icon-more-vertical"></i>
            </a>
        </li>
    </ul>
</div>


<div class="layui-side layui-bg-black">
    <div class="layui-side-scroll">
        <ul class="layui-nav layui-nav-tree" lay-filter="test" id="menu">

        </ul>
    </div>
</div>
<script>
    var res = <?php echo $layout_menu_list_json; ?>

    $("#menu").html('')
    layui.use('element', function () {
        element = layui.element;
        //console.log(res)
        let header = '';
        res.forEach( v => {
            header += `
                            <li class="layui-nav-item" id="header_${v.id}"><a href="javascript:;">${v.title}</a></li>
                        `
            var content = '<li class="layui-nav-item">';
            if(v.position == 0 && v.status == 1 && v.show == 1){
                content += '<a href="javascript:;">' + v.title + '</a>';
                content += loadchild(v);
                content += '</li>';
            }
            //这里是添加所有的子菜单
            $("#menu").append(content);
        })
        $('#layuiHeader').html(header)

        element.init();

        // 表头点击事件
        $("#layuiHeader").on("click", 'li', function() {
            // 表头添加样式
            $.each($(this).siblings(), function (i, e) {
                $(e).find("a").removeClass('layui-this')
            });
            $(this).find("a").addClass('layui-this');

            // 侧边栏
            let id = $(this).attr("id").split('_')[1];
            //console.log(id)
            let newArr = res.filter( v => {
                return v.id == id
            })
            // console.log(newArr[0])

            $("#menu").html('');

            newArr.forEach( v => {
                var content = '<li class="layui-nav-item">';
                if(v.position == 0 && v.status == 1 && v.show == 1) {
                    content += '<a href="javascript:;">' + v.title + '</a>';
                    //这里是添加所有的子菜单
                    content += loadchild(v);
                    content += '</li>';
                }
                $("#menu").append(content);
            })
            element.init();

        })
    });


    //组装子菜单的方法
    function loadchild(obj) {
        if (obj == null) {
            return;
        }
        var content = '';
        if (obj.child != null && obj.child.length > 0) {
            content += '<dl class="layui-nav-child">';
        } else {
            content += '<dl>';
        }

        if (obj.child != null && obj.child.length > 0) {
            $.each(obj.child, function (i, note) {
                if(note.position == 0 && note.status == 1 && note.show == 1) {
                    content += '<dd>';
                    content += '<a href="' + note.route + '" onclick="viewClick(' + note.parent_id + ')">' + note.title + '</a>';
                    if (note.child == null) {
                        return;
                    }
                    content += loadchild(note);
                    content += '</dd>';
                }
            });

            content += '</dl>';
        }
        //console.log(content);
        return content;
    }

    // 侧边栏点击事件
    function viewClick(parent_res_id) {
        //console.log(parent_res_id);
        $('#header_' + parent_res_id)
        $.each($('#header' + parent_res_id).siblings(), function (i, e) {
            $(e).find("a").removeClass('layui-this')
        });
        $('#header_' + parent_res_id).find("a").addClass('layui-this');
    }
</script>

    <div class="layui-body">
        <div class="layui-bg-gray" style="padding: 5px;">
            <div class="layui-row layui-col-space15">
                <div class="layui-col-md12">
                    <div class="layui-panel">
                        <div style="padding: 0.5rem 1rem;">
                            <span class="layui-breadcrumb" lay-separator="—">
                            <?php foreach($menuAllParent as $key=>$vo): if($vo['isChild'] == '1'): ?>
                                    <a><cite><?php echo htmlentities($vo['title']); ?></cite></a>
                                <?php else: ?>
                                    <a href="<?php echo htmlentities($vo['route']); ?>"><?php echo htmlentities($vo['title']); ?></a>
                                <?php endif; ?>
                            <?php endforeach; ?>
                            </span>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="layui-bg-gray" style="padding: 5px;">
            <div class="layui-row layui-col-space15">
                <div class="layui-col-md12">
                    <div class="layui-panel">
                        <div style="padding: 0.5rem 1rem;">
                            <div style="padding: 15px;">

<div class="layui-form" id="menu_add"> <!-- 提示：如果你不想用form，你可以换成div等任何一个普通元素 -->
    <div class="layui-form-item">
        <label class="layui-form-label">文章标题</label>
        <div class="layui-input-block">
            <input type="text" name="title" placeholder="请输入" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">文章分类</label>
        <div class="layui-input-block">
            <input type="text" name="category_id" placeholder="请输入" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">文章内容</label>
        <div class="layui-input-block">
            <textarea name="content" placeholder="文章内容" class="layui-textarea"></textarea>
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit lay-filter="*">立即提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
    <!-- 更多表单结构排版请移步文档左侧【页面元素-表单】一项阅览 -->
</>
<script>
    layui.use('form', function(){
        var form = layui.form;

        //各种基于事件的操作，下面会有进一步介绍
        form.on('submit(*)', function(data){
            // console.log(data.elem) //被执行事件的元素DOM对象，一般为button对象
            // console.log(data.form) //被执行提交的form对象，一般在存在form标签时才会返回

            if(!data.field['title']){
                layer.msg('文章标题不能为空');
                return false;
            }
            if(!data.field['content']){
                layer.msg('文章内容不能为空');
                return false;
            }

            var addArray = data.field;

            console.log(addArray) //当前容器的全部表单字段，名值对形式：{name: value}

            $.ajax({
                url: "/admin/article/add",
                type: "POST",
                data:{
                    'addArray':addArray,
                },
                dataType: "json",
                success: function(result){
                    console.log(result)
                    if(result.code === 0){
                        layer.confirm(result.msg+',请选择下一步操作', {
                            btn: ['继续添加','返回列表页'] //按钮
                        }, function(){
                            location.reload();
                        }, function(){
                            window.location='/admin/article/index'
                        });
                    }else{
                        layer.msg(result.msg)
                    }
                },
                error:function(err){
                    layer.msg(result.msg)
                    console.log(err.statusText);
                }
            });
            return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
        })
    });
</script></div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <!--<div class="layui-footer">-->
<!--    &lt;!&ndash; 底部固定区域 &ndash;&gt;-->
<!--    底部固定区域-->
<!--</div>-->

<script>
    //JS
    layui.use(['element', 'layer', 'util'], function(){
        var element = layui.element
            ,layer = layui.layer
            ,util = layui.util
            ,$ = layui.$;

        //头部事件
        util.event('lay-header-event', {
            //左侧菜单事件
            menuLeft: function(othis){
                layer.msg('展开左侧菜单的操作', {icon: 0});
            }
            ,menuRight: function(){

                layer.open({
                    type: 1
                    ,content: '<div id="msgList"></div>'
                    ,area: ['260px', '100%']
                    ,offset: 'rt' //右上角
                    ,anim: 5
                    ,shadeClose: true
                });
                var html = '';
                $.ajax({
                    url: "http://1.117.149.125:81/api/msgList",
                    type: "GET",
                    data:{
                        'data':'',
                    },
                    dataType: "json",
                    success: function(data){
                        data['data'].forEach(function(item) {
                            console.log(item);
                            html += '<div style="padding: 15px;">'+item['content']+'</div>';
                        });
                        $('#msgList').html(html);
                    },
                    error:function(err){
                        console.log(err.statusText);
                    }
                });
            }
        });

    });
</script>
</div>

</body>
</html>